<!--
 * @author gaohailan
 -->
<template>
  <div class="app-container essay-seclection-container">
    <el-collapse-transition>
      <div v-show="searchshow" class="common-search merge">
        <span class="svg-container">
          <svg-icon icon-class="search" />
        </span>
        <el-input v-model="listQuery.title" clearable placeholder="按新闻标题进行搜索" class="search-input" @keyup.enter.native="handleFilter" />
        <div class="common-search-btn">
          <el-button class="filter-item" type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">更多筛选条件<i class="el-icon-arrow-down" /></span>
        </div>
      </div>
    </el-collapse-transition>
    <el-collapse-transition>
      <div v-show="!searchshow" class="common-search separate">
        <div class="common-search-inner">
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">征文标题</div>
                <el-input v-model="listQuery.title" clearable class="filter-item" style="width: 100%;" placeholder="请输入征文标题搜索" />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">作者</div>
                <el-input v-model="listQuery.editorName" clearable class="filter-item" style="width: 100%;" placeholder="请输入作者搜索" />
              </div>
            </el-col>
            <el-col :span="8">
              <div class="search-inner-item">
                <div class="item-label">是否评为优秀</div><!---是否优秀 0 否 1是-->
                <el-select v-model="listQuery.isGood" placeholder="请选择">
                  <el-option key="0" :value="0" label="否"/>
                  <el-option key="1" :value="1" label="是"/>
                </el-select>
              </div>
            </el-col>
          </el-row>
        </div>
        <div class="common-search-btn">
          <el-button type="primary" @click="handleFilter">{{ $t('table.search') }}</el-button>
          <el-button class="filter-item" type="primary" @click="resettingBtn">重置</el-button>
          <span class="common-search-more" @click="searchshow = !searchshow">精简筛选条件<i class="el-icon-arrow-up" /></span>
        </div>
      </div>
    </el-collapse-transition>
    <div class="common-btn">
      <div class="btn-title">
        <span>活动问题</span>
      </div>
    </div>
    <div class="table">
      <el-table
        v-loading="listLoading"
        :data="honorList"
        class="tableScope"
        :header-cell-style="rowClass"
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"/>
        <el-table-column prop="title" label="征文标题" show-overflow-tooltip/>
        <el-table-column prop="editorName" label="作者" show-overflow-tooltip/>
        <el-table-column prop="compName" label="机构名称" show-overflow-tooltip/>
        <el-table-column prop="crtTime" label="提交时间" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.crtTime ? scope.row.crtTime.substring(0,10) : '' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="isGood" label="是否评为优秀" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{ scope.row.isGood=='1'?'是':'否' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="200" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button v-if="scope.row.isGood=='1'" type="text" size="mini" @click="handelDel(scope.row)">取消优秀</el-button>
            <el-button v-if="scope.row.isGood=='1'" type="text" size="mini" @click="answer(scope.row)">回答</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize" @pagination="getList"/>
  </div>
</template>
<script>
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
  // import { queryPageActivityArticle, deletes,insertOrUpd ,updateActivityArticle} from '@/api/business/workerStudy'
  export default {
    name: 'ReasonableQuestion',
    components: { Pagination },
    data() {
      return {
        searchshow: true,
        listLoading: false,
        total: 0,
        listQuery: {
          page: 1,
          pageSize: 10,
          title: '',
          activityId: '',
          editorName: '',
          isGood: ''
        },
        multipleSelection: [],
        honorList: [],
      }
    },
    created() {
      /*this.listQuery.activityId = this.$route.query.id;
      this.getList()*/
    },
    methods: {
      answer(item){
        this.$router.push({path: '/reasonable/reasonableAnswer', name: 'ReasonableAnswer', query: {id: item.id,rowData:item}})
      },
      rowClass({ row, rowIndex }) {
        return {
          padding: '5px 0',
          height: '20px',
          background: 'rgba(247,247,248,1)'
        }
      },
      handleSelectionChange(arr) {
        this.multipleSelection = arr
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      resettingBtn() {
        this.listQuery.title = ''
        for (const i in this.listQuery) {
          this.listQuery['' + i + ''] = ''
        }
        this.listQuery.page = 1;
        this.listQuery.pageSize = 10;
        this.listQuery.activityId = this.$route.query.id;
        this.getList()
      },
      handleCreate() {
        this.$router.push({path: '/workerStudy/edit', name: 'WorkerStudyEdit'})
      },
      handelDel(row) {
        this.deleteHonor(row.id)
      },
      handleDeletes() {
        const arr = []
        if (this.multipleSelection.length > 0) {
          this.multipleSelection.forEach(item => {
            arr.push(item.id)
          })
          var ids = arr.join(',')
          this.deleteHonor(ids)
        } else {
          this.$message({
            message: '请选择需要删除的数据！',
            type: 'warning'
          })
        }
      },
      getList(obj) {
        this.listLoading = true
        return new Promise((resolve, reject) => {
          queryPageActivityArticle(this.listQuery).then(response => {
            this.honorList = response.data.data.rows
            this.total = response.data.data.total
            setTimeout(() => {
              this.listLoading = false
            }, 1 * 1000)
          }).catch(error => {
            reject(error)
            setTimeout(() => {
              this.listLoading = false
            }, 1 * 1000)
          })
        })
      },
      deleteHonor(ids) {
        this.$confirm('此操作将取消优秀数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          return new Promise((resolve, reject) => {
            updateActivityArticle({id:ids,isGood:0}).then(() => {
              this.$notify({
                title: '成功',
                message: '取消优秀成功',
                type: 'success',
                duration: 2000
              })
              this.getList()
            }).catch(error => {
              reject(error)
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消取消优秀'
          })
        })

      }
    }
  }
</script>
<style rel="stylesheet/scss" lang="scss">
  $dark_gray: #bfced6;
  $dark_main: #18A5FD;
  $mainColor: #18A5FD;
  .essay-seclection-container {
    .common-search{
      background-color: #fff;
      padding: 0 20px;
      .svg-container {
        padding: 0;
        color: $dark_gray;
        vertical-align: middle;
        display: inline-block;
        &_login {
          font-size: 20px;
        }
      }
      .search-input{
        width: 60%;
        position: relative;
        &:after{
          content: "";
          position: absolute;
          left: -25px;
          right: 0;
          bottom: 8px;
          height: 1px;
          background:rgba(226,227,232,1);
        }
        input{
          outline:none;
          background:transparent;
          border:none;
          outline:medium;
          padding: 0;
          &:focus{
            outline: none;
            background-color: transparent;
          }
        }
      }
      .common-search-btn{
        display: inline-block;
        float: right;
        .el-button.is-round{
          padding: 10px 30px;
          margin-right: 34px;
        }
        .common-search-more{
          font-size: 14px;
          font-weight: 500;
          color: $mainColor;
          cursor: pointer;
          margin-left: 10px;
        }
      }
      &.merge{
        height: 50px;
        line-height: 50px;
      }
      &.separate{
        .common-search-inner{
          padding-top: 10px;
          .search-inner-item{
            .item-label{
              height: 30px;
              line-height: 30px;
              font-size: 14px;
              color: #A6A6A6;
              font-weight:400;
            }
            .el-input{
              position: relative;
              .el-input__inner{
                border: none;
                padding: 0;
              }
              &:after{
                content: "";
                height: 1px;
                background-color: #E2E3E8;
                position: absolute;
                left: 0;
                right: 0;
                bottom: 0;
              }
            }
          }
        }
        .common-search-btn{
          text-align: center;
          display: block;
          float: none;
          height: 56px;
          line-height: 56px;
        }
      }
    }
    .common-btn {
      display: flex;
      height: 36px;
      line-height: 36px;
      margin-bottom: 10px;
      .btn-title {
        flex: 1;
        font-size: 16px;
        font-weight: bold;
        font-family: PingFangSC-Medium;
        color: rgba(51, 51, 51, 1);
      }
    }
    .el-dialog {
      .el-dialog__body {
        padding: 20px;
      }
      .el-dialog__footer {
        border-top: 1px solid #E2E3E8;
        padding: 15px 20px;
      }
    }
  }
</style>
